package com.xpresso.utils.unitTests.email;

import java.util.ArrayList;

import com.xpresso.utils.email.EmailConfiguration;
import com.xpresso.utils.email.EmailProcessor;
import com.xpresso.utils.email.ProcessedMessage;
import com.xpresso.utils.email.SimpleMailboxManager;
import com.xpresso.utils.exceptions.XpressoException;

import junit.framework.TestCase;

public class TestEmailProcessor extends TestCase {
	
	public void testEmailProcessor(){
		System.out.println("Testing Email Processor ...");
		EmailConfiguration ec = new EmailConfiguration();
		ec.setHost("mail.picwing.com");
		ec.setUser("collectorman@picwing.com");
		ec.setPass("iphone");
		ec.setAttachmentPath("C:/Enrique/Projects/Socialbum/WebContent/pic2web/");
		
		EmailProcessor ep = new EmailProcessor();
		ep.setEmailconf(ec);
		SimpleMailboxManager mManager = new SimpleMailboxManager(ep);
		
		try {
			ArrayList<ProcessedMessage> pMessages = mManager.runEmailReader();
			for (ProcessedMessage message:pMessages){
				System.out.println(message.getFrom() + " - " + message.getSentDate());
				System.out.println("Body: " + message.getMessageBody());
				for (String file:message.getAttachments()){
					System.out.println("     - " + file);
				}
			}
		} catch (XpressoException e) {
			e.getTheException().printStackTrace();
			fail();
		}
		
	}	
	
}
